<template>
  <div>
    <el-table :data="tableData" style="width: 100%; opacity: 0.7">
      <el-table-column label="出发时间" width="140">
        <template #default="scope">
          <div style="display: flex; align-items: center">
            <span style="text-align: center">{{ scope.row.startDate }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="车次/类型" width="140">
        <template #default="scope">
          <p>{{ scope.row.carone }}</p>
          <p>{{ scope.row.cartype }}</p>
        </template>
      </el-table-column>
      <el-table-column label="出发/始发站">
        <template #default="scope">
          <p><el-tag>始</el-tag>{{ scope.row.startLocation }}</p>
          <p><el-tag type="success">终</el-tag>{{ scope.row.endLocation }}</p>
        </template>
      </el-table-column>
      <el-table-column label="出发/始发时间" width="140">
        <template #default="scope">
          <div>
            <p>{{ scope.row.startTime.split(" ")[1].slice(0, 5) }}</p>
            <p>{{ scope.row.endTime.split(" ")[1].slice(0, 5) }}</p>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="历时" width="140">
        <template #default="scope">
          <p>{{ scope.row.far }}</p>
          <p>当日到达</p>
        </template>
      </el-table-column>
      <el-table-column label="坐席" width="140">
        <template #default="scope">
          <p>
            <span
              >软卧:<span class="sp">{{ scope.row.softsleeper }}</span></span
            ><span
              >商务座:<span class="sp">{{ scope.row.hardsleeper }}</span></span
            >
          </p>
          <p>
            <span
              >硬卧:<span class="sp">{{ scope.row.hardsleeper }}</span></span
            ><span
              >一等座:<span class="sp">{{ scope.row.softsleeper }}</span></span
            >
          </p>
          <p>
            <span
              >硬座:<span class="sp">{{ scope.row.softsleeper }}</span></span
            ><span
              >二等座:<span class="sp">{{ scope.row.hardsleeper }}</span></span
            >
          </p>
          <p>无座</p>
        </template>
      </el-table-column>
      <el-table-column label="提交状态" width="140">
        <template #default="scope">
          <p>{{ scope.row.submitStatus }}</p>
        </template>
      </el-table-column>
      <el-table-column label="状态" width="140">
        <template #default="scope">
          <el-switch v-model="scope.row.status"> </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <p>
            <el-button size="small" @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
          </p>
          <p>
            <el-button
              size="small"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </p>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { defineProps, ref, defineEmits } from "vue";

const props = defineProps({
  tableData: {
    type: Array,
  },
  currentPage: {
    type: Number,
  },
  pageSize: {
    type: Number,
  },
});
// console.log(currentPage);
// 实例化自定义事件
const emit = defineEmits();
const handleEdit = (index, row) => {
  console.log(index);
  //  // 通知父组件进行编辑
  emit("edit", {
    id: row.id,
    row,
    index,
    currentPage: props.currentPage,
    pageSize: props.pageSize,
  });
};
const handleDelete = (index, row) => {
  // 通知父组件进行删除
  emit("del", {
    id: row.id,
    index,
    currentPage: props.currentPage,
    pageSize: props.pageSize,
  });
};
</script>

<style scoped>
.sp {
  color: #ff8d41;
}
</style>